//
//  ViewController.swift
//  Demo 17 AVAudioRecorder进行录音
//
//  Created by quanhao huang on 2019/12/27.
//  Copyright © 2019 quanhao huang. All rights reserved.
//

import UIKit
import AVFoundation

/**
 AVAudioRecorder也需要强引用防止其被意外释放
 并且需要告诉用户使用NSMicrophoneUsageDescription权限，否则会导致崩溃
 */

class ViewController: UIViewController {
    
    var audioRecorder:AVAudioRecorder!

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let destinationURL = URL.init(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).last!)
        do {
            try audioRecorder = AVAudioRecorder(url: destinationURL, settings: [:])
        } catch  {
            print(error)
        }
        
        audioRecorder.prepareToRecord()
        //开始录音
        audioRecorder.record()
        /**
             //暂停录音
             audioRecorder.pause()
             //结束录音
             audioRecorder.stop()
         */
        
    }


}

